package com.zeny.express.framework.mq;

import com.zeny.express.framework.shared.serializer.Serializer;

public abstract class AbstractMqClient<T> {
	
	public static final int DATA_FORMAT_BINARY = 1;
	public static final int DATA_FORMAT_TEXT = 2;
	protected Serializer<T> dataBinarySerializer;
	protected Serializer<T> dataTextSerializer;
	protected int dataFormat = DATA_FORMAT_BINARY;
	
	private String className;
	private Class<?> clazz;
	
	protected AbstractMqPool<?> mqPool;
	
	public int getDataFormat() {
		return dataFormat;
	}

	public void setDataFormat(int dataFormat) {
		this.dataFormat = dataFormat;
	}

	protected Serializer<T> getDataSerializer(int dataFormat) {
		if (DATA_FORMAT_BINARY == dataFormat) {
			return dataBinarySerializer;
		} else {
			return dataTextSerializer;
		}
	}
	
	public String getClassName() {
		return className;
	}
	
	public void setClassName(String className) throws ClassNotFoundException {
		this.className = className;
		
		clazz = Class.forName(className);
	}

	@SuppressWarnings("rawtypes")
	protected Class getDataClass()
	{
		return clazz;
	}

	public AbstractMqPool<?> getMqPool() {
		return mqPool;
	}

	public void setMqPool(AbstractMqPool<?> mqPool) {
		this.mqPool = mqPool;
	}
	
	public abstract T get();
	public abstract void put(final T data);
}
